package com.cloud.shopping.goods.controller;

import com.cloud.shopping.cart.model.Cart;
import com.cloud.shopping.goods.model.Sku;
import com.cloud.shopping.goods.service.SkuService;
import com.cloud.shopping.tool.RespResult;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author John.zhang
 * @version Id: SkuController, v 1.0 2020/12/29 17:18 ZhiYong Exp $
 */
@Api(tags = "商品SKU模块")
@RestController
@RequestMapping(value = "/sku")
public class SkuController {

    @Resource
    private SkuService skuService;


    /***
     * 库存递减
     */
    @PostMapping(value = "/dCount")
    public RespResult dCount(@RequestBody List<Cart> carts) {
        skuService.dCount(carts);
        return RespResult.ok();
    }


    /**
     * 根据ID查询商品详情
     *
     * @param id id
     * @return Sku
     */
    @GetMapping(value = "/{id}")
    public RespResult<Sku> one(@PathVariable(value = "id") String id) {
        Sku sku = skuService.getById(id);
        return RespResult.ok(sku);
    }


    /**
     * 根据推广分类查询推广产品列表
     *
     * @param id id
     * @return List
     */
    @GetMapping(value = "/adItems/type")
    public List<Sku> typeItems(Integer id) {
        List<Sku> skuas = skuService.typeSkuItems(id);
        return skuas;
    }

    /**
     * 根据推广分类删除推广产品列表
     */
    @DeleteMapping(value = "/adItems/delete")
    public RespResult delTypeItems(@RequestParam(value = "id") Integer id) {
        skuService.delTypeSkuItems(id);
        return RespResult.ok();
    }

    /**
     * 根据推广分类查修改推广产品列表
     */
    @PutMapping(value = "/adItems/update")
    public RespResult updateTypeItems(@RequestParam(value = "id") Integer id) {
        skuService.updateTypeSkuItems(id);
        return RespResult.ok();
    }


}
